import requests


def send_single_sms(apikey, code, mobile):
    # 发送单条短信
    url = "https://sms.yunpian.com/v2/sms/single_send.json"
    text = f"【刘昌富测试】您的验证码是{code}"
    res = requests.post(url, data={
        "apikey": apikey,
        "mobile": mobile,
        "text": text
    })
    # re_json = json.loads(res.text)
    return res.json()


if __name__ == "__main__":
    res = send_single_sms("fba4cf1c5ba93b7119cd1722af951b24", "1234", "18620206545")
    # res_json = json.loads(res.text)
    code = res["code"]
    msg = res["msg"]
    if code == 0:
        print("发送成功")
    else:
        print(f"发送失败: {msg}")
    print(res)
